/*
 * ScreenManager.h
 *
 *  Created on: 10/09/2011
 *      Author: Aeradon
 */

#ifndef SCREENMANAGER_H_
#define SCREENMANAGER_H_

#include <SDL2/SDL.h>
#include <GL/glew.h>
#include <string>

#include "Utils.h"

void ScreenManagerCallBack(void* obj);

class Triangulation;
class NavimeshRenderer;

class ScreenManager
{
public:
	static const int SCR_DEF_WIDTH  = 1000;
	static const int SCR_DEF_HEIGHT = 1000;
	static const int SCR_DEF_BPP    = 32;

	unsigned int count_index;
	unsigned int count_coord;
	unsigned int count_color;
	unsigned int count_vertex;
	float colorR, colorG, colorB;

	// Number of Objects and vectors
	static const int MAX_OBJECTS =  3000;
	GLfloat objectVertices[MAX_OBJECTS *9];
	GLfloat objectColors[MAX_OBJECTS *12];

	GLfloat zoom;
	GLfloat viewPortX1, viewPortY1, viewPortX2, viewPortY2;
	GLfloat cameraX, cameraY;
	GLint resolutionW, resolutionH;

public:
	static ScreenManager* GetInstance();
	virtual ~ScreenManager();

	int  InitGL();
	int  LoadGLTextures();
	void updateCamera();
	int  RenderTriangles();
	int  RenderLines();
	int  Render();
	void addVertex(float x, float y, float z, GLColor color);
	void clearBuffers();
	void Present();
	void ClearScreen();

	void UpdateZoom(float percent);
	void resizeEvent(int w, int h);
	void testRenderer();
	void saveScreenShot();

	/// Triangualtion realted Methods
	Triangulation* triangulation;
	NavimeshRenderer* meshRenderer;
	void RenderTriangulation();
	void RenderConstraints(bool only = 0);
	void ShowTriangulation();
	void ShowConstraints(bool only = 0);
	bool renderTriangulation;
	/// Triangulation Related Methods

private:
	ScreenManager();
	static ScreenManager* instance;
	SDL_Window * window;
	SDL_GLContext glContext;

	void printFramebufferInfo();
	bool checkFramebufferStatus();

	std::string getTextureParameters(GLuint id);
	std::string getRenderbufferParameters(GLuint id);
	std::string convertInternalFormatToString(GLenum format);
};

#endif /* SCREENMANAGER_H_ */


